using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Forum.Business
{
    public class ThreadView : ForumUserControl
    {
        protected Repeater updateDate_list;
        protected Repeater viewCount_list;
        protected Repeater replyCount_list;
        protected Repeater recommended_list;

        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack && !AjaxManager.IsCallBack)
            {
                BindData(0, 10);
            }
        }

        private void BindData(int pageIndex, int pageSize)
        {
            if (updateDate_list != null)
            {
                ThreadListRequest request = new ThreadListRequest();
                request.PageIndex = pageIndex;
                request.PageSize = pageSize;
                updateDate_list.DataSource = BusinessManager.GetThreads(RequestHelper.BuildGetThreadViewListRequest(request, (int)ThreadOrderType.UpdateDate));
                updateDate_list.DataBind();
            }
            if (viewCount_list != null)
            {
                ThreadListRequest request = new ThreadListRequest();
                request.PageIndex = pageIndex;
                request.PageSize = pageSize;
                viewCount_list.DataSource = BusinessManager.GetThreads(RequestHelper.BuildGetThreadViewListRequest(request, (int)ThreadOrderType.ViewCount));
                viewCount_list.DataBind();
            }
            if (replyCount_list != null)
            {
                ThreadListRequest request = new ThreadListRequest();
                request.PageIndex = pageIndex;
                request.PageSize = pageSize;
                replyCount_list.DataSource = BusinessManager.GetThreads(RequestHelper.BuildGetThreadViewListRequest(request, (int)ThreadOrderType.ReplyCount));
                replyCount_list.DataBind();
            }
            if (recommended_list != null)
            {
                ThreadListRequest request = new ThreadListRequest();
                request.PageIndex = pageIndex;
                request.PageSize = pageSize;
                request.ThreadStatus = (int)ThreadStatus.Recommended;
                recommended_list.DataSource = BusinessManager.GetThreads(RequestHelper.BuildGetThreadViewListRequest(request, (int)ThreadOrderType.UpdateDate));
                recommended_list.DataBind();
            }
        }
    }
}